/*
 * SuperGame.java
 *
 * Created on 28 March 2007, 01:38
 */

package example.greatgame;

import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;

public class SuperGame extends MIDlet implements CommandListener
{
    private Display mDisplay = null;
    private Form mForm;
    private TextField mTextField;
    private StringItem mLabel;
    private Command mCmdSayHello;
    private Command mCmdSayGoodbye;
    private int m_jaySucks = 0;

    public SuperGame()
    {
        // Create form
        mForm = new Form("Example Form");
        // Create text field and append it to the form
        mTextField = new TextField("Enter your name", "", 20, TextField.ANY);
        mForm.append(mTextField);
        // Create label and append it to the form
        mLabel = new StringItem("", "");
        
        mForm.append(mLabel);
        // Create commands and add to form
        mCmdSayHello = new Command("Say Hello", Command.SCREEN, 1);
        mCmdSayGoodbye = new Command("Say Goodbye", Command.SCREEN, 1);
        Command exitCommand = new Command("Exit", Command.EXIT, 0);
        mForm.addCommand(mCmdSayHello);
        mForm.addCommand(mCmdSayGoodbye);
        mForm.addCommand(exitCommand);
        mForm.setCommandListener(this);
    }

    protected void startApp() throws MIDletStateChangeException 
    {
        if (mDisplay == null)
        {
            mDisplay = Display.getDisplay(this);
        }
        mDisplay.setCurrent(mForm);
    }

    protected void pauseApp()
    {
        
    }

    protected void destroyApp(boolean unconditional) throws MIDletStateChangeException
    {
        
    }

    public void commandAction(Command c, Displayable s)
{
        if (c.getCommandType() == Command.EXIT)
        {
            notifyDestroyed();
        }
        else if (c == mCmdSayHello)
        {
            m_jaySucks++;
            mLabel.setText("\nJay sucks " + String.valueOf(m_jaySucks) + " times!\n");
        }
        else if (c == mCmdSayGoodbye)
        {
            m_jaySucks+=10;
            mLabel.setText("\nWhat, " + mTextField.toString() + "?? Goodbye??\nWell, Jay sucks " + String.valueOf(m_jaySucks) + " times!\n");
        }

    }

}
//
//
//public class SuperGame extends MIDlet implements Runnable
//{
//    public Canvas thisGraphics;
//    public Form newForm;
//    
//    public void startApp()
//    {
//        Display currentDisplay = Display.getDisplay(this);
//        
//        newForm = new Form("JaySucks!");
//        
//        int screenSizeX = 240;
//        int screenSizeY = 320;
//        
//        Random randomNum = new Random();
//        
//        //while (true)
//        //{
//            //newForm.
//
//        //}
//        
//        Thread newThread = new Thread(this);
//        newThread.start();
//    }
//    
//    public void pauseApp()
//    {
//        
//    }
//    
//    public void destroyApp(boolean unconditional)
//    {
//        
//    }
//
//    public void run()
//    {
//        String nextString = "";
//        
//        int tempNum = 0;
//        while (true)
//        {
//            nextString = "Jay sucks!";
//            nextString += " ";
//            nextString += tempNum;
//            nextString += " times!";
//            
//            newForm.append( nextString );
//            try {
//                wait(100);
//            } catch (InterruptedException ex) {
//                ex.printStackTrace();
//            }
//            
//            tempNum++;
//        }
//    }
//}